package com.db.ionio.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author Alexander Kotov (kotov.alex.22@gmail.com)
 */
public class FileNIOCopier {

    public static void main(String[] args) throws Exception {

        if (args.length < 2) {
            System.out.format("Usage: %s <source> <destination>%n", FileNIOCopier.class.getName());
            System.exit(1);
        }

        final String src = args[0];
        final String dst = args[1];

        long start = System.nanoTime();

        try (
                FileChannel in = new FileInputStream(new File(src)).getChannel();
                FileChannel out = new FileOutputStream(new File(dst)).getChannel()) {
            out.transferFrom(in, 0, in.size());
        }

        long time = System.nanoTime() - start;
        System.out.println(time);
    }
}
